<?php
class Interview_model extends CI_Model {

    function __construct()
    {
        parent::__construct();
    }
    
    function get($data)
    {
    	$this->db->select('interview.*');
    	$this->db->from('interview');
    	
    	if (isset($data['idinterview'])) {
    		$this->db->where('interview.id', $data['idinterview']);
    	}
    	
    	$this->db->order_by('interview.id desc');
    	
    	return $this->db->get();
    }
    
	function insert($data)
    {
    	$this->db->trans_begin();
    	
    	$data_insert = array(
		   'idcandidate' => $data['idcandidate'],
		   'idcompany' => $data['idcompany'],
		   'idsession' => (string)$data['session_id']
		);
		
		$this->db->set('startdate', 'NOW()', false);
		$this->db->insert('interview', $data_insert);
		
		$this->db->set('idmemberfrom', $this->session->userdata['idmember']);
		$this->db->set('idmemberfromtype', 2);
		$this->db->set('idmemberto', '(select idmember from candidate where candidate.id = '.$data['idcandidate'].')', false);
		$this->db->set('idmembertotype', 1);
		$this->db->set('idinterview', $this->db->insert_id());
		$this->db->set('idtype', 5);
		$this->db->set('message', '');
		$this->db->set('date', 'NOW()', false);
		$this->db->insert('message');
		
    	if ($this->db->trans_status() === false)
		{
		    $this->db->trans_rollback();
		    return false;
		}
		else
		{
		    $this->db->trans_commit();
		    return true;
		}
    }
}
?>